package com.zzx.schoolfellow.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzx.schoolfellow.mapper.ChatMessageMapper;
import com.zzx.schoolfellow.mapper.UmsUserMapper;
import com.zzx.schoolfellow.model.dto.ChatMessageDTO;
import com.zzx.schoolfellow.model.entity.ChatMessage;
import com.zzx.schoolfellow.model.entity.UmsUser;
import com.zzx.schoolfellow.service.ChatMessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

@Service
public class ChatMessageServiceImpl implements ChatMessageService {
    @Resource
    private ChatMessageMapper chatMessageMapper;
    @Resource
    private UmsUserMapper umsUserMapper;

    @Override
    public ChatMessage createMessage(ChatMessageDTO messageDTO) {
        ChatMessage message = new ChatMessage();
        message.setContent(messageDTO.getContent());
        message.setSender(messageDTO.getSender());
        message.setReceiver(messageDTO.getReceiver());
        message.setCreateTime(LocalDateTime.now());
        chatMessageMapper.insert(message);
        return message;
    }


    public List<ChatMessage> getMessages() {
        return chatMessageMapper.selectList(null);
    }

    @Override
    public List<ChatMessage> getMessage(String id) {
        return null;
    }

    public List<ChatMessage> getMessage(String username, String authorName) {
        QueryWrapper<ChatMessage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sender", username).eq("receiver", authorName);
        return chatMessageMapper.selectList(queryWrapper);
    }

    public void deleteMessage(String id) {
        chatMessageMapper.deleteById(id);
    }


    public void sendMessage(ChatMessage message) {
        message.setIsRead(false);
        chatMessageMapper.insert(message);
    }

    @Override
    public List<ChatMessage> getMessageList(Integer fromUser, Integer toUser) {
        return chatMessageMapper.selectMessageList(fromUser, toUser);
    }


    @Override
    public boolean saveBatch(Collection<ChatMessage> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<ChatMessage> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<ChatMessage> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(ChatMessage entity) {
        return false;
    }

    @Override
    public ChatMessage getOne(Wrapper<ChatMessage> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<ChatMessage> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<ChatMessage> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public BaseMapper<ChatMessage> getBaseMapper() {
        return null;
    }

    @Override
    public Class<ChatMessage> getEntityClass() {
        return null;
    }
}
